package com.huawei.M01.iterator;

/**
 * 检查一个数组是不是好数组
 *
 * @author zhiwu
 */
public class GoodArray {
    public boolean isGoodArray(int[] nums) {
        int gcd = nums[0];
        if (nums.length == 1) {
            return gcd == 1;
        }
        for (int i = 1; i < nums.length; i++) {
            gcd = gcd(gcd, nums[i]);
            if (gcd == 1) {
                return true;
            }
        }
        return false;
    }

    private int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }
}
